package com.yangguang.huahui.ui.adapters;

import android.widget.ImageView;

import com.yangguang.huahui.R;
import com.yangguang.huahui.baseadapter.BaseQuickAdapter;
import com.yangguang.huahui.baseadapter.BaseViewHolder;
import com.yangguang.huahui.entity.Nongzi;
import com.yangguang.huahui.utils.CommonUtil;
import com.yangguang.huahui.utils.ImageLoader;

import java.util.Calendar;
import java.util.List;

/**
 * Created by Administrator on 2017/3/7.
 */

public class NongziAdapter extends BaseQuickAdapter<Nongzi.ListBean>{
    private int type;
    public NongziAdapter(int layoutResId, List<Nongzi.ListBean> data) {
        super(layoutResId, data);
    }
    public NongziAdapter(int layoutResId, List<Nongzi.ListBean> data, int type) {
        super(layoutResId, data);
        this.type = type;
    }

    @Override
    protected void convert(BaseViewHolder helper, Nongzi.ListBean item) {
        ImageLoader.load(mContext, item.getCarousel(), (ImageView) helper.getView(R.id.iv_goods));
        helper.setText(R.id.tv_goods_name, item.getGoods_title());
        helper.setText(R.id.tv_address, item.getSource_of_supply_name());
        helper.setText(R.id.tv_price, "￥"+ item.getPrice());
        if (!CommonUtil.isNull(item.getRelease_time())) {
            helper.setText(R.id.tv_date, CommonUtil.longToTime(Long.parseLong(item.getRelease_time()+"000"), Calendar.DATE));
        }else {
            helper.setText(R.id.tv_date, "");
        }
        if (type == 1){
            helper.setVisible(R.id.tv_sell_type, false);
        }else {
            helper.setVisible(R.id.tv_sell_type, true);
            helper.setText(R.id.tv_sell_type, item.getSell_lease_type());
        }
        if (!CommonUtil.isNull(item.getAuthentication())){
            switch (Integer.valueOf(item.getAuthentication())){
                case 1:
                    helper.setImageResource(R.id.iv_auth, R.mipmap.icon_ren_gray);
                    helper.setText(R.id.tv_auth, mContext.getResources().getString(R.string.auth_no));
                    break;
                case 2:
                    helper.setImageResource(R.id.iv_auth, R.mipmap.icon_ren_green);
                    helper.setText(R.id.tv_auth, mContext.getResources().getString(R.string.auth_yes));
                    break;
            }
        }
        if (!CommonUtil.isNull(item.getKetubbah())){
            switch (Integer.valueOf(item.getKetubbah())){
                case 1:
                    helper.setImageResource(R.id.iv_ketubbah, R.mipmap.icon_bao_gray);
                    helper.setText(R.id.tv_ketubbah, mContext.getResources().getString(R.string.pay_bao_no));
                    break;
                case 2:
                    helper.setImageResource(R.id.iv_ketubbah, R.mipmap.icon_bao_green);
                    helper.setText(R.id.tv_ketubbah, mContext.getResources().getString(R.string.pay_bao_yes));
                    break;
            }
        }
    }
}
